package com.itheima.app.cotroller;

import com.itheima.app.manager.SettingManager;
import com.itheima.domain.db.Notification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingController {

    @Autowired
    private SettingManager settingManager;
    //查询通用设置
    @GetMapping("/users/settings")
    public ResponseEntity findSettingVo(){
        return settingManager.findSettingVo();
    }

    //添加问题
    @PostMapping("/users/questions")
    public void setQuestion(@RequestBody Map<String,String> map){
        String content = map.get("content");
        settingManager.setQuestion(content);
    }

    //添加通知
    @PostMapping("/users/notifications/setting")
    public void setNotification(@RequestBody Notification param){
        settingManager.setNotification(param);
    }

    /*起别名和默认值*/
    //黑名单分页查询
    @GetMapping("/users/blacklist")
    public ResponseEntity findBlackListByPage(@RequestParam(value="page" ,defaultValue = "1") Integer pageNum ,@RequestParam(value="pagesize" , defaultValue = "10") Integer pageSize){
        /*设置默认的页大小，使用RequestParam*/
        return settingManager.findBlackListByPage(pageNum,pageSize);
    }

    //黑名单移除
    @DeleteMapping("/users/blacklist/{uid}")
    public void removeBlackList(@PathVariable("uid") Long blackUserId){
        settingManager.removeBlackList(blackUserId);
    }
}
